package com.example.viewdemo

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.example.viewdemo.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity(), View.OnClickListener {
    private lateinit var binding:ActivityMainBinding
    private lateinit var test3Tv:TextView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()


        binding=ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.ViewBindingTv.text="View Binding跳转TestTextView"

        binding.ViewBindingTv.setOnClickListener{
            val data ="text test 发送"
            val intent =Intent(this,TestTextView::class.java)
            intent.putExtra("extra_data", data)
            startActivity(intent)
        }



//        setContentView(R.layout.activity_main)

        val testTV: TextView =findViewById(R.id.mainTv)
        testTV.text="findViewById 跳转TestTextView2"

        testTV.setOnClickListener{
//            val intent =Intent(this,TestTextview2::class.java)

            val intent =Intent("com.example.VIEW_TEXTVIEW2")

            startActivity(intent)
            Toast.makeText(this,"test clicked textview", Toast.LENGTH_SHORT).show()
        }


        val test2TV: TextView =findViewById(R.id.textView8)
        test2TV.text="findViewById 跳转默认游览器"

        test2TV.setOnClickListener{

            val intent =Intent(Intent.ACTION_VIEW)
            intent.data = Uri.parse("https://www.baidu.com")

//            val intent =Intent(Intent.ACTION_DIAL)
//            intent.data = Uri.parse("tel：10086")
            startActivity(intent)
            Toast.makeText(this,"跳转默认游览器", Toast.LENGTH_SHORT).show()
        }

        test3Tv =findViewById(R.id.alertDialogtest)
        test3Tv.text="AlertDialog"

        test3Tv.setOnClickListener(this)

    }

    override fun onClick(v: View?) {
        when(v){
            test3Tv -> {
                val intent =Intent(this,AlertDialogActivity::class.java)
                startActivity(intent)
            }


        }
    }

    private fun showAlertDialog() {

    }

}

